home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
130 MIDI Tool Box
/
130 MIDI Tool Box.iso
/
czdump02
/
czdump02.bas
next >
Wrap
BASIC Source File
|
1987-07-03
|
14KB
|
387 lines
SCREEN 0,0,0 : COLOR 7,1,1 : CLS : LOCATE 3,1
?" ***************************************************************************"
?" * *"
?" * FileName: CZDUMP02.BAS, CZDUMP02.EXE *"
?" * For IBM, ROLAND MPU-401, with CASIO CZ-101/CZ-1000 or other CZ Synths *"
?" * *"
?" * CZDUMP02 puts your MPU-401 into its 'DUMB UART' mode and then gets *"
?" * a patch dump of the CZ Bank and Voice of your choice, from PRESET *"
?" * No. 1 to 16, INTERNAL 1 to 16, CARTRIDGE 1 to 16, or the Sound Area. *"
?" * This is done on MIDI Channel 1. To run, connect your CZ-101 (on *"
?" * MIDI Channel 1) to the MPU-401 OUT and also the MPU-401 IN. *"
?" * Then type CZDUMP02 <Return>. Use arrow keys to select the Bank *"
?" * and Voice to be dumped. Hit ENTER to get the data, <ESC> to EXIT. *"
?" * Don't play notes on your keyboard, screen will fill with data. *"
?" * Compile ONLY with TURBO BASIC Ver. 1.0 on IBM PC/XT or equiv. *"
?" * Please feel free to tinker around to learn about MIDI! *"
?" * *"
?" * By Gino F. Silvestri 06/24/87 22:22 Hrs. *"
?" * *"
?" ***************************************************************************"
PRINT : PRINT TAB(25) "Press Space Bar to continue"
WHILE NOT INSTAT : WEND ' Wait for a keypress here
' ***************************************************************************
' * D E F I N I T I O N S *
' ***************************************************************************
DEFINT A-Z
' TURBO BASIC Constants:
%ComdPort = &H331 ' MPU-401 Command Port on IBM
%StatPort = &H331 ' MPU-401 Status Port on IBM
%DataPort = &H330 ' MPU-401 Data I/O Port on IBM
%DRR = &H40 ' Mask for Data Read Reg. Bit
%DSR = &H80 ' Mask for Data Set Ready Bit
%MaskFlip = &HFF ' WAIT Function Bit Mask XOR
%TimeOut = 5 ' Tests before declaring dead
%MPUReset = &HFF ' MPU-401 Total Reset Command
%UARTMode = &H3F ' MPU-401 "Dumb UART Mode"
%ForeColor1 = 7 ' White
%ForeColor2 = 6 ' Brown
%ForeColor3 = 14 ' Yellow
%Black = 0 ' Black Background & Border
%Blue = 1 ' Blue Background & Border
%Red = 4 ' Red Background for Errors
%Flash = 16 ' Add 16 to Color to Flash
' ---------------------------------------------------------------------------
DATA &HF0,&H44,&H00,&H00,&H70,&H10 : REM Dump Req. Code
' Byte: 1 2 3 4 5 6 7
' >>>>>>>>>>>>>>>>>>> Dump Code String translation: <<<<<<<<<<<<<<<<<<<<<<<
' Bytes 1 & 2 : &HF0, &H44 = CASIO System Exclusive Header (ALWAYS)
' Bytes 3 & 4 : &H00, &H00 = Filler
' Byte 5 : &H70 = MIDI Chan.1 (&H71 through &H7F for MIDI Chans. 2 to 16)
' Byte 6 : &H10 = Indicates that this is a Send Request 1 Type Message
REM Form Feed
' Byte 7 : (Variable) Which Patch : &H20 = INTERNAL 1, (00 to 0F OR 10
' to 1F are PRESET 1 to 16; 20-2F OR 30-3F = INTERNAL 1 to 16;
' 40-4F OR 50-5F = CARTRIDGE 1 to 16; &H60 = SOUND AREA
DATA &H70,&H31 : REM Go-Ahead Code
' ---------------------------------------------------------------------------
StartMsg$ = "CZDUMP02 - CZ Voice Dump Demo - SELECT Bank, Voice"
Entr$ = " Bank (up/down), Voice (left/right), ENTER to dump :"
Str1$ = " Dump Request of "
Str1A$ = "Sent -> TO CZ-101 : "
Str2$ = " Dump Request Acknowledge <------- FROM CZ-101 : "
Str3$ = " Send Go - Ahead to DUMP ----------> TO CZ-101 : "
Str4$ = " Dump of "
Str4A$ = " <----------- FROM CZ-101 : (256 Bytes) "
Str5$ = " END of REQUEST ACK Sent ----------> TO CZ-101 : "
TransMsg$ = ">>>>>>> CZ Patch Transmission in Progress <<<<<<<"
EndMsg$ = "Dump Complete - Select again or hit <ESC> to EXIT"
ErrMsg$ = " MPU-401 or CZ-101 Not Responding! - EXITING "
Bank$ = "INTERNAL " ' Init. Bank Name
PatchDesired = &H20 ' Default patch to request
Bank = 1 ' Default Bank to request
Patch = 1 ' Default Patch = 1
DEF FNIndent(St$) = INT((80 - LEN(St$))/2) ' Calculate Centered Indent
' ---------------------------------------------------------------------------
' ***************************************************************************
' * I N I T I A L I Z A T I O N *
' ***************************************************************************
RSTMPU: ' Reset the MPU-401
CLS ' Clear Display
OUT %ComdPort,%MPUReset ' Send MPU-401 RESET Command
A = INP(%DataPort) ' Dummy read to clear buffer
DELAY .5 ' Wait for port to settle
IF INP(%StatPort) >&HC0 THEN GOTO ErrExit ' Quit if MPU-401 Not Ready
WAIT %StatPort,%DRR,%MaskFlip ' Wait for port ready
OUT %ComdPort,%UARTMode ' Set MPU-401 "Dumb UART" Mode
A = INP(%DataPort) ' Dummy Read to clear buffer
WAIT %StatPort,%DSR,%MaskFlip ' Wait for "UART" port ready -
' Really crucial!
REM Form Feed
' ***************************************************************************
' * M A I N P R O G R A M *
' ***************************************************************************
Start:
COLOR %ForeColor1,%Blue,%Blue ' White on Blue
CLS
DELAY .5 ' Wait for screen to settle.
LOCATE 2,FNIndent(StartMsg$) ' Center Text
PRINT StartMsg$;
LOCATE 4,1
PRINT Entr$;
GOSUB UpDisp ' Display Initial Parameters
KEY (11) ON ' Enable UP Arrow Key
KEY (12) ON ' DOWN Arrow Key
KEY (13) ON ' LEFT Arrow Key
KEY (14) ON ' RIGHT Arrow Key
ON KEY (11) GOSUB BankInc ' UP Arrow = Increment Bank
ON KEY (14) GOSUB BankDec ' DOWN Arr. = Decrement Bank
ON KEY (13) GOSUB PatchInc ' LEFT Arr. = Decrement Patch
ON KEY (12) GOSUB PatchDec ' RIGHT Arr. = Increment Patch
' ---------------------------------------------------------------------------
HandleKey: ' Main Wait Loop
In$ = INKEY$ ' Get any keypress
IF In$ = CHR$(13) THEN GOTO WantDump ' DUMP on ENTER
IF In$ = CHR$(27) THEN END ' QUIT on ESC
IF In$ = "E" OR In$ = "e" THEN END ' EXIT if 'E' Also
GOTO HandleKey
' ---------------------------------------------------------------------------
REM Form Feed
' ---------------------------------------------------------------------------
'| O N K E Y Subroutines |
' ---------------------------------------------------------------------------
BankInc: ' UP arrow pressed
INCR BankSel
IF BankSel >4 THEN BankSel = 1 ' Reset if past 4
GOTO BankChange ' Handle Change in Bank
BankDec: ' DOWN arrow-Dec. Bank
DECR BankSel
IF BankSel <1 THEN BankSel = 4 ' Back to 4 if 0
GOTO BankChange ' Handle Change in Bank
PatchDec: ' LEFT arrow-Dec. Patch
DECR Patch
IF Patch = 0 THEN Patch = 16 ' Back to 16 if 0
GOTO PatchChange ' Handle Patch Change
PatchInc: ' RIGHT arrow-Inc.Patch
INCR Patch '
IF Patch = 17 THEN Patch = 1
GOTO PatchChange ' Handle Patch Change
GOTO HandleKey ' Don't leave yet
' ---------------------------------------------------------------------------
BankChange: ' Handle Bank Select Change
SELECT CASE BankSel ' Process Bank Type
CASE 1 ' If BankSel = 1
Bank = 0
Bank$ = "PRESET "
CASE 2
Bank = &H20
Bank$ = "INTERNAL "
CASE 3
Bank = &H40
Bank$ = "CARTRIDGE"
CASE 4
Bank = &H60
Bank$ = " Sound Area "
Patch = 1 ' Force Patch to 1 for SndArea
PatchDesired = &H60 ' Force request code also
' Fall through to BankSet
END SELECT
' ---------------------------------------------------------------------------
REM Form Feed
BankSet: ' Update Bank Code to send
PatchDesired = PatchDesired AND &H0F ' Kill Left Nibble
PatchDesired = PatchDesired + Bank ' Add New Value
GOTO UpDisp
' ---------------------------------------------------------------------------
PatchChange: ' Modify patch No. to send
PatchDesired = PatchDesired AND &HF0 ' Kill Right Nibble
IF Bank = &H60 THEN Patch = 1 : GOTO UpDisp ' Sound Area = ONLY &H60
PatchDesired = PatchDesired + Patch -1 ' Add New Value (0 to 15)
' Fall through to UpDisp
' ---------------------------------------------------------------------------
UpDisp: ' Display Bank and Patch Data
LOCATE 4,56
COLOR %ForeColor3,%Red,%Red ' In Yellow on Red
PRINT " "; Bank$;
IF BANK = &H60 THEN GOTO Skipatch ' Don't display a # for this
LOCATE 4,66
PRINT Patch ;
Skipatch:
COLOR %ForeColor1,%Blue,%Blue ' Back to regular colors
LOCATE 6,1 ' New Line following
RETURN
' ---------------------------------------------------------------------------
REM Form Feed
' ---------------------------------------------------------------------------
'| W A N T D U M P - Main display function begins |
' ---------------------------------------------------------------------------
WantDump: ' Tell CZ: "I want a DUMP"
COLOR %ForeColor3,%Red,%Red ' Yellow on Red
LOCATE 24,FNindent(TransMsg$) '
PRINT TransMsg$; ' "Transmission" Msg.
COLOR %ForeColor2,%Blue,%Blue ' Brown on Blue
LOCATE 6,1
PRINT Str1$; Bank$; Patch; Str1A$;
RESTORE ' Reinit DATA Pointer
FOR N = 1 to 6 ' Send 6 bytes of Req. to CZ
READ C ' Get DATA to send
PRINT HEX$(C);" "; ' Show what we sent
A = INP(%DataPort) ' Dummy Read
GOSUB OutChar ' Send one character
NEXT
C = PatchDesired ' Now send Patch Wanted Code
PRINT HEX$(C);" "; ' Show what we sent
A = INP(%DataPort) ' Dummy Read
GOSUB OutChar ' Send one character
PRINT : PRINT
' ---------------------------------------------------------------------------
GetAck: ' CZ Acks: "Ready to DUMP".
COLOR %ForeColor3,%Blue,%Blue ' Yellow on Blue
PRINT Str2$;
TimeOut = %TimeOut ' Prepare for deadman timeout
WHILE A <> &H30 ' Wait for last CZ Char.
WHILE (INP(%StatPort) AND %DSR) = %DSR ' Wait for Input Data
DECR TimeOut : IF TimeOut = 0 THEN GOTO ErrExit ' If no Reply
WEND
A = INP(%DataPort) ' Get Char. FROM CZ
PRINT HEX$(A);" "; ' Display code from CZ
WEND
PRINT : PRINT
' ---------------------------------------------------------------------------
REM Form Feed
TellOK: ' Tell CZ "OK, then, DUMP"
COLOR %ForeColor2,%Blue,%Blue ' Brown on Blue
PRINT Str3$;
FOR N = 1 to 2 ' Sending only 2 bytes
READ C ' From DATA statements
PRINT HEX$(C);" "; ' Show what we sent
A = INP(%DataPort) ' Dummy Read
GOSUB OutChar ' Send out a character
NEXT
PRINT : PRINT
' ---------------------------------------------------------------------------
DispDump: ' Display the CZ Dump.
COLOR %ForeColor3,%Blue,%Blue ' Yellow on Blue
PRINT Str4$ ; Bank$; Patch; Str4A$ : PRINT
CC = 0 ' Count of chars per line.
PRINT " "; ' Init. Blank Space
WHILE A <> &HF7 ' Get Entire dump until F7
WAIT %StatPort,%DSR,%MaskFlip ' Wait for Data ready
A = INP(%DataPort)
PRINT HEX$(A);" "; ' Display what we got from CZ
INCR CC : IF CC = 37 THEN PRINT : PRINT " "; : CC = 0 'New Line
WEND
PRINT : PRINT
' ---------------------------------------------------------------------------
SendLastAck: ' Send CZ the last ACK.
COLOR %ForeColor2,%Blue,%Blue ' Brown on Blue
C = &HF7 ' Last ACK to CZ
GOSUB OutChar ' Send it out
PRINT Str5$; HEX$(C) ' Show what was sent
' ---------------------------------------------------------------------------
REM Form Feed
ThatsAll:
COLOR %ForeColor1,%Blue,%Blue ' White on Blue
LOCATE 24,FNindent(EndMsg$) '
PRINT EndMsg$; ' "End" Msg.
GOTO HandleKey ' Back for more work
END ' END of Main Program
' ---------------------------------------------------------------------------
ErrExit: ' QUIT if I/O failure
COLOR %ForeColor3+%Flash,%Red,%Red ' Flashing Yellow on Red
CLS ' Reinit Screen to ALL Red
LOCATE 10,1,0 ' Position Error Message
Indent = FNIndent(ErrMsg$) ' Calculate Centered Indent
PRINT TAB(Indent)CHR$(201);STRING$(LEN(ErrMsg$),205);CHR$(187)
PRINT TAB(Indent)CHR$(186);SPACE$(LEN(ErrMsg$));CHR$(186)
PRINT TAB(Indent)CHR$(186);ErrMsg$;CHR$(186)
PRINT TAB(Indent)CHR$(186);SPACE$(LEN(ErrMsg$));CHR$(186)
PRINT TAB(Indent)CHR$(200);STRING$(LEN(ErrMsg$),205);CHR$(188)
'
DELAY 6 ' Show Flashing Error a while
END ' Exit on I/O Failure.
' ---------------------------------------------------------------------------
' ***************************************************************************
' * S U B R O U T I N E S *
' ***************************************************************************
' **************************** OutChar SUBROUTINE ***************************
OutChar: ' Send Data Byte to CZ-101
OUT %DataPort,C ' Send Char. out
A = INP(%DataPort) ' Dummy Read to clear buffer
TimeOut = %TimeOut ' Init. deadman count
WHILE (INP(%StatPort) AND %DRR) = %DRR ' Wait for port ready
DECR TimeOut : IF TimeOut = 0 THEN GOTO ErrExit ' Yipes! Quit
WEND
RETURN
END
' ************************* Last Line of CZDUMP02.BAS ************************
' Last Edited 07/03/87 2115 Hrs. G. F. Silvestri